package edu.qhst.user.controller.inner;

import edu.qhst.common.constant.ApiRouterConsts;
import edu.qhst.common.resp.BaseResponse;
import edu.qhst.common.resp.ResultUtils;
import edu.qhst.user.dto.UserSafeInfoDto;
import edu.qhst.user.service.UserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 用户微服务内部调用接口
 *
 * @author 加浓美式
 * @date 2023/6/23
 */
@Tag(name = "InnerUserController", description = "内部调用-用户模块")
@RestController
@RequestMapping(ApiRouterConsts.API_INNER_USER_URL_PREFIX)
@RequiredArgsConstructor
public class InnerUserController {
    private final UserService userService;

    /**
     * 批量查询用户信息
     */
    @Operation(summary = "批量查询用户信息")
    @PostMapping("listUserInfoByIds")
    BaseResponse<List<UserSafeInfoDto>> listUserInfoByIds(@RequestBody List<Long> userIds) {
        return ResultUtils.success(userService.listUserInfoByIds(userIds));
    }

    /**
     * 获取当前用户信息
     *
     * @param userId
     * @return
     */
    @Operation(summary = "根据id获取用户")
    @GetMapping("/getUserById")
    public UserSafeInfoDto getUserById(Long userId) {
        return userService.getUserById(userId);
    }

    /**
     * 获取当前用户权限
     *
     * @param loginUser
     * @return
     */
    @Operation(summary = "查看用户权限")
    @PostMapping("/isAdmin")
    public boolean getUserRole(UserSafeInfoDto loginUser) {
        return userService.isAdmin(loginUser);
    }
}
